
We are going to analyze the evolution of Spain economy from 2002 to 2020, based on macro-economic data, such as:
The data was collected from the following sources: INE (Instituto Nacional de Estadística), datosmacro.com, and Ministerio de Hacienda.
Our analysis goes from 2002 to 2020, because the moment where we are analyzing the data is December-2021, so we don't have full 2021 data.
Spain is the country with the highest unemployment rate in Europe, and one of the world highest. We want to analyze this evolution.
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import plotly
plotly.offline.init_notebook_mode()
from plotly.subplots import make_subplots
import seaborn as sns
sns.set(rc={'figure.figsize':(14,10)}, style='whitegrid')
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
We have obtained several datasets, and we have combined them into a single one.
data = pd.read_csv('../spain_data.csv')
data.head()
Our dates are in int format. The data values represents the last day of the year, so we can format the dates to represent that day.
years = []
for year in data['year'].values:
years.append(str(year) + '-12-31')
data['year'] = years
data['year'] = pd.to_datetime(data['year'])
data.head()
The remaining data is numeric, as we want.
data.info()
Let's plot correlations between variables
sns.heatmap(data.corr(), annot=True, cmap='Greens');
We can see that lot of variables have correlations between them. We can notice that the majority of total_private_employment correlations are negative. This is specially striking if we look at the correlation with unemployment_rate. The more total private employment, the less unemployment rate.
The unemployment_rate is highly correlated with total_spending_over_pib, mean_salary —this makes sense since unemployment rate in Spain growths over time in this period, like the mean salary—. debt_over_pib and debt_per_capita is highly correlated with unemployment_rate aswell.
We want to analyze the unemployment rate, because is the main problem of Spain (if we talk about economics); also the public debt is a problem to this country.
Let's see the evolution of the unemployment between 2002-2020:
fig = px.line(data, x='year', y=data['unemployment_rate(%)'],
title='Spain - Evolution of Unemployment Rate 2002-2020',
template='plotly_white', markers=True)
fig.update_layout(height=400, width=900, template='plotly_white',
autosize=False, showlegend=False)
fig.show()
From 2008 the unemployment rate growths to about 26% (2013-2014), it starts to goes down until 2020, where starts to growth again (this can be related with COVID-19 pandemic).
As we saw before, the unemployment rate is highly correlated with the spendings over PIB and debt over PIB. Let's plot this variables:
fig = make_subplots(rows=2, cols=1, shared_xaxes=False,
subplot_titles=('Spain - Evolution of Public Spendings over GDP',
'Spain - Evolution of Debt over GDP'))
fig.append_trace(go.Scatter(x=data['year'], y=data['total_spending_over_pib'],
mode='lines+markers', name='Public Spendings over GDP',
line=dict(color='#d62728')), row=1, col=1)
fig.append_trace(go.Scatter(x=data['year'], y=data['debt_over_pib(%)'],
mode='lines+markers', name='Debt over GDP (%)',
line=dict(color='#2ca02c')), row=2, col=1)
fig.update_layout(height=900, width=1100, template='plotly_white',
autosize=False, showlegend=True)
fig.show()
We can scale the data to plot the evolution of the three variables.
data.loc[0, ['unemployment_rate(%)', 'total_spending_over_pib', 'debt_over_pib(%)']]
scaled_variables = data[['year', 'unemployment_rate(%)', 'total_spending_over_pib', 'debt_over_pib(%)']]
scaled_variables['unemployment_rate(%)'] = scaled_variables['unemployment_rate(%)'] * 4.41
scaled_variables['total_spending_over_pib'] = scaled_variables['total_spending_over_pib'] * 1.326
scaled_variables[['unemployment_rate(%)', 'total_spending_over_pib', 'debt_over_pib(%)']] = scaled_variables[['unemployment_rate(%)', 'total_spending_over_pib', 'debt_over_pib(%)']]/51.2
fig = px.line(scaled_variables, x='year', y=scaled_variables.columns[1:],
title='Spain - Evolution of Unemployment Rate, Public Spendings and Debt 2002-2020',
template='plotly_white', markers=True)
fig.update_layout(height=500, width=1100, template='plotly_white',
autosize=False, showlegend=True)
fig.show()
Here we can see that the unemployment rate wants to follow the debt over PIB; total public spendings over PIB changes are not so agressive. However, the shape of this variable moves like the other two, so this can be consequence of cause of the unemployment rate, or at least there exist some relationship between them.
Let's analyze the evolution of GDP in Spain, and the related variables.
fig = make_subplots(rows=2, cols=1,
subplot_titles=('Spain - Evolution of GDP 2002-2020',
'Spain - Evolution of Debt over GDP 2002-2020'))
fig.append_trace(go.Scatter(x=data['year'], y=data['PIB_total(M€)'],
mode='lines+markers', name='Total GDP (Millions)',
line=dict(color='orange')), row=1, col=1)
fig.append_trace(go.Scatter(x=data['year'], y=data['debt_over_pib(%)'],
mode='lines+markers', name='Debt over GDP (%)',
line=dict(color='grey')), row=2, col=1)
fig.update_layout(height=700, width=1000, template='plotly_white',
autosize=False, showlegend=False)
fig.show()
GROWTH OF BOTH INDICES:
gdp_growth = -100 + 1121.94 / 749.55 * 100
gdp_debt_growth = -100 + 120 / 51.2 * 100
fig = px.bar(x=['GDP Growth', 'Debt over GDP Growth'], y=[gdp_growth, gdp_debt_growth],
title='Spain - GDP and Debt over GDP Growth 2002-2020',
template='plotly_white', labels={
"x": "",
"y": "Growth %"})
fig.update_layout(height=400, width=900, template='plotly_white',
autosize=False, showlegend=False)
fig.show()
SCALED VALUES:
scaled_val = data[['year', 'PIB_total(M€)', 'debt_over_pib(%)']]
scaled_val['PIB_total(M€)'] = scaled_val['PIB_total(M€)'] / 14639.6875
scaled_val[['PIB_total(M€)', 'debt_over_pib(%)']] = scaled_val[['PIB_total(M€)', 'debt_over_pib(%)']] / 52.1
fig = px.bar(scaled_val, x='year', y=scaled_val.columns[1:],template='plotly_white',
title='Spain - Evolution of GDP and Debt over GDP (scaled values)')
fig.update_layout(height=400, width=1000,
autosize=False, showlegend=True)
fig.show()
scaled_val = data[['year', 'PIB_total(M€)', 'debt_over_pib(%)']]
scaled_val['PIB_total(M€)'] = scaled_val['PIB_total(M€)'] / 14639.6875
scaled_val[['PIB_total(M€)', 'debt_over_pib(%)']] = scaled_val[['PIB_total(M€)', 'debt_over_pib(%)']] / 52.1
fig = px.line(scaled_val, x='year', y=scaled_val.columns[1:],template='plotly_white',
title='Spain - Evolution of GDP and Debt over GDP (scaled values)')
fig.update_layout(height=400, width=1000,
autosize=False, showlegend=True)
fig.show()
The spanish GDP raises about 50% from 2002 to 2020 (from about 0.8B€ to 1.2B€), however the debt over GDP raises from 50% to 120%, about 140%, almost three times the GDP growth. The debt over GDP was 35% in 2007, and raises to 100% in only seven years (2014). In the last year, the debt over GDP raises 20%, from 100% to 120%. This can be related with the total public spendings:
fig = px.line(data, x='year', y=data['total_public_spendings'],
title='Spain - Evolution of Public Spendings 2002-2020',
template='plotly_white', markers=True)
fig.update_layout(height=400, width=900, template='plotly_white',
autosize=False, showlegend=False)
fig.show()
It's interesting how the public spendings raises like the unemployment rate. This variable is closely related with the GDP growth aswell (obviously), but we can notice that the GDP growths about 50% —as we said before— while public spendings growth was about 100% —the double— in the same time period.
Let's analyze the public and private employment. As we saw, spanish public spendings were doubled in less than 20 years, so makes sense that public employment raises aswell. We can see in the next plot that the same does not happen with private employment:
fig = make_subplots(rows=2, cols=1,
subplot_titles=('Spain - Evolution of Public Employment 2002-2020',
'Spain - Evolution of Private Employment 2002-2020'))
fig.append_trace(go.Scatter(x=data['year'], y=data['total_public_employment'],
mode='lines+markers', name='Public Employments',
line=dict(color='red')), row=1, col=1)
fig.append_trace(go.Scatter(x=data['year'], y=data['total_private_employment'],
mode='lines+markers', name='Private Employments',
line=dict(color='blue')), row=2, col=1)
fig.update_layout(height=700, width=900, template='plotly_white',
autosize=False, showlegend=False)
fig.show()
GROWTH OF BOTH KIND OF EMPLOYMENTS 2002-2020:
public_emp_growth = -100 + (3.337 / 2.649) * 100
private_emp_growth = -100 + (15.839 / 14.27) * 100
fig = px.bar(x=['Public Employment Growth', 'Private Employment Growth'], y=[public_emp_growth, private_emp_growth],
title='Spain - Public and Private Employment Growth 2002-2020',
template='plotly_white', labels={
"x": "",
"y": "Growth %"})
fig.update_layout(height=400, width=900, template='plotly_white',
autosize=False, showlegend=False)
fig.show()
SCALED VALUES:
scaled_val = data[['year', 'total_private_employment', 'total_public_employment']]
scaled_val['total_private_employment'] = scaled_val['total_private_employment'] / 5.387
scaled_val[['total_public_employment', 'total_private_employment']] = scaled_val[['total_public_employment', 'total_private_employment']] / 2649000
fig = px.bar(scaled_val, x='year', y=scaled_val.columns[1:],template='plotly_white',
title='Spain - Evolution of Public and Private Employment (scaled values)')
fig.update_layout(height=400, width=900,
autosize=False, showlegend=True)
fig.show()
scaled_val = data[['year', 'total_private_employment', 'total_public_employment']]
scaled_val['total_private_employment'] = scaled_val['total_private_employment'] / 5.387
scaled_val[['total_public_employment', 'total_private_employment']] = scaled_val[['total_public_employment', 'total_private_employment']] / 2649000
fig = px.line(scaled_val, x='year', y=scaled_val.columns[1:],template='plotly_white',
title='Spain - Evolution of Public and Private Employment (scaled values)')
fig.update_layout(height=400, width=1000,
autosize=False, showlegend=True)
fig.show()
fig.write_html("file.html")
As we can see, maybe one of the more related variables with the high unemployment rate is the debt over GDP and public spendings.
It's difficult analyze this kind of problems only with data, since there exists a lot of external, economic and social factors that can directly affect the unemployment in a country. But it's obviously that Spain did something wrong, because they're leading the unemployment-rate table in Europe.
The public employment growths with the unemployment rate, while private employment does the other way —when private employment growths, unemployment falls. Maybe one of the keys will be focus on private employment and try to waste less money in public spendings/public employment, because the data says that the private employment is more related with economic health than public employment.